package com.zhongkai.app.controller;

import com.zhongkai.app.service.AppHomeUnitService;
import com.zhongkai.model.utils.ZhongkaiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * APP首页
 * */
@Controller
public class AppHomeUnitController {

    @Autowired
    private AppHomeUnitService appHomeUnitService;


    /**
     * 获取用户设备列表
     * @param app_uuid 用户uuid
     *
     * */
    @RequestMapping(value = "/unit_user_app/list", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult unitDate(String app_uuid) {

        ZhongkaiResult result = appHomeUnitService.appUnitList(app_uuid);

        return result;
    }




    /**
     *  获取用户名下设备列表
     * @param app_uuid 用户uuid
     *
     * */
    @RequestMapping(value = "/unit_user_app/list_role", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult appUnitListRole(String app_uuid) {

        ZhongkaiResult result = appHomeUnitService.appUnitListRole(app_uuid);

        return result;

    }





    /**
     * 添加子用户
     * @param app_uuid 用户uuid
     * @param unit_uiid 机组uuid
     * @param phone 用户手机号
     * @param code 验证码
     * @param name 姓名
     * @param relation_id 关系列表id
     *
     * */
    @RequestMapping(value = "/unit_user_app/add_son", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult addUnitSon(String app_uuid,String unit_uiid,String phone,String code,String name,@RequestParam(defaultValue = "100")Integer relation_id) {

        ZhongkaiResult result = appHomeUnitService.addUnitSon(app_uuid,unit_uiid,phone,code,name,relation_id);

        return result;
    }





    /**
     * 修改子用户
     *
     * @param phone       子用户手机号
     * @param name        姓名
     * @param relation_id 关系列表id
     * @param fsonid      关系列表id
     */
    @RequestMapping(value = "/unit_user_app/update_son", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult updateUnitSon(String phone, String name, @RequestParam(defaultValue = "0")Integer relation_id, @RequestParam(defaultValue = "0")Integer fsonid) {

        ZhongkaiResult result = appHomeUnitService.updateUnitSon(phone,name,relation_id,fsonid);

        return result;
    }


    /**
     * 删除子用户
     * @param phone 子用户手机号
     * @param app_uuid 父用户uuid
     * */
    @RequestMapping(value = "/unit_user_app/remove_son", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult removeUnitSon(String app_uuid,String phone) {

        ZhongkaiResult result = appHomeUnitService.removeUnitSon(app_uuid,phone);

        return result;
    }



    /**
     *亲戚关系列表
     * */
    @RequestMapping(value = "/unit_user_app/relation", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult relationList() {

        ZhongkaiResult result = appHomeUnitService.relationList();

        return result;
    }



    /**
     * 子用户列表
     * @param app_uuid 用户uuid
     * @param page
     * @param rows
     * */
    @RequestMapping(value = "/unit_user_app/unit_son_list", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult relationList(String app_uuid, @RequestParam(defaultValue = "0") Integer page,  @RequestParam(defaultValue = "0") Integer rows) {

        ZhongkaiResult result = appHomeUnitService.unitSonList(app_uuid,page,rows);

        return result;
    }


    /**
     * 设备托管
     *
     * @param unit_uuid  设备uuid
     * @param trusteeship  托管参数 1取消托管  2托管
     */
    @RequestMapping(value = "/unit_user_app/trusteeship", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult uniTrusteeship(String unit_uuid,String trusteeship) {

        ZhongkaiResult result = appHomeUnitService.uniTrusteeship(unit_uuid,trusteeship);

        return result;
    }


    /**
     * 报警信息列表
     * @param unit_uuid 设备uuid
     * @param page
     * @param rows
     * */
    @RequestMapping(value = "/unit_user_app/unlike_list", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult unlikeList(String unit_uuid,@RequestParam(defaultValue = "0")Integer page,@RequestParam(defaultValue = "0") Integer rows) {

        ZhongkaiResult result = appHomeUnitService.unlikeList(unit_uuid,page,rows);

        return result;
    }
}
